package github.ziwukun.jsonql.lang;

import java.util.function.Consumer;

public class JSONQLBuilder {
	Select select;
	String from;
	Where where;
	Limit limit;
	Sort sort;
	JSONQLBuilder(){}
	
	
	public JSONQLBuilder select(Consumer<SelectBuilder> consumer) {
		SelectBuilder select = new SelectBuilder();
		consumer.accept(select);
		this.select = select.build();
		
		return this;
	}
	
	public JSONQLBuilder from(String from) {
		this.from = from;
		
		return this;
	}
	
	public JSONQLBuilder where(Consumer<WhereBuilder> consumer) {
		WhereBuilder whereBuilder = new WhereBuilder(null, null);
		consumer.accept(whereBuilder);
		this.where = whereBuilder.build();
		
		return this;
	}
	
	public JSONQLBuilder limit(Consumer<LimitBuilder> consumer) {
		LimitBuilder limitBuilder = new LimitBuilder();
		consumer.accept(limitBuilder);
		this.limit = limitBuilder.build();
		
		return this;
	}
	
	public JSONQLBuilder sort(Consumer<SortBuilder> consumer) {
		SortBuilder sortBuilder = new SortBuilder();
		consumer.accept(sortBuilder);
		this.sort = sortBuilder.build();
		
		return this;
	}
	
	public JSONQL build() {
		return new JSONQLImpl(select,from,where,limit,sort);
	}
}
